<template>
  <div>
    <!-- <title-name title="考察信息填写链接"></title-name>
    <a-form-model
        ref="ruleForm"
        :model="labourList"
        :label-col="{span: 6 }"
        :wrapper-col="{span: 18 }"
        :rules="rules">
      <a-row>
        <a-col  :md="10" :sm="10">
          <a-form-model-item
                  :wrapperCol="{ lg: { span: 24 }, sm: { span: 24 } }">
            <BaseInput :disabled="disabled" placeholder="请输入" style="width:500px"  />
          </a-form-model-item>
        </a-col>
        <a-col>
          <a-button :disabled="disabled"  style="margin:0 20px" type="primary">复制链接</a-button>
          <a-button  :disabled="disabled"  type="primary">生成二维码</a-button>
        </a-col>
      </a-row>
    </a-form-model> -->
    <title-name title="分包商基础信息" />
    <a-form-model
      ref="ruleForm1"
      :model="labourList.subcontractorBase"
      :label-col="{span: 6 }"
      :wrapper-col="{span: 18 }"
      :rules="rules"
    >
      <a-row>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="分包商名称"
            prop="subcontractorName"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.subcontractorName"
              disabled
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="公司成立时间"
            prop="companyCreateTime"
          >
            <!-- <BaseInput v-model="form.subcontractorBase.companyCreateTime"
                    placeholder="请输入"  /> -->
            <a-date-picker
              v-model="labourList.subcontractorBase.companyCreateTime"
              :disabled="disabled"
              @change="changecompanyCreateTime"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="注册资金(万)"
            prop="registerCapital"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.registerCapital"
              type="number"
              :disabled="disabled"
              :max-length="5"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="企业办公地址是否固定"
            prop="isFixed"
            class="radio-box"
          >
            <a-radio-group
              v-model="labourList.subcontractorBase.isFixed"
              :disabled="disabled"
              name="radioGroup"
              :default-value="1"
            >
              <a-radio value="1">
                固定
              </a-radio>
              <a-radio value="2">
                不固定
              </a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="办公地址"
            prop="address"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.address"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="法定代表人姓名"
            prop="legalName"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.legalName"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="法定代表人电话"
            prop="legalPhone"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.legalPhone"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="统一社会信用代码"
            prop="license"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.license"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="资质证书编号"
            prop="qualificationCertificate"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.qualificationCertificate"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="资质类别等级"
            prop="qualityLevel"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.qualityLevel"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="安全生产许可证编号"
            prop="securityCode"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.securityCode"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="联系人姓名"
            prop="investigateName"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.investigateName"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="联系人电话"
            prop="investigatePhone"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.investigatePhone"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="实际负责人姓名"
            prop="acturalName"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.acturalName"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="实际负责人电话"
            prop="acturalPhone"
          >
            <BaseInput
              v-model="labourList.subcontractorBase.acturalPhone"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <!-- <a-button @click="save">保存</a-button> -->
    </a-form-model>
    <title-name
      style="margin-top:20px"
      title="企业主要管理人员"
    />
    <company :labour-list="labourList" />
    <title-name
      style="margin-top:20px"
      title="近三年主要业绩"
    />
    <achievement :labour-list="labourList" />
    <title-name
      style="margin-top:20px"
      title="合作三年以上的班组"
    />
    <team :labour-list="labourList" />
    <title-name
      style="margin-top:20px"
      title="在建项目考察情况"
    />
    <a-form-model
      ref="ruleForm2"
      :model="labourList.constructionProject"
      :label-col="{span: 6 }"
      :wrapper-col="{span: 18 }"
      :rules="rules"
    >
      <a-row>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="目前在施项目个数"
            prop="count"
          >
            <BaseInputNumber
              v-model="labourList.constructionProject.count"
              :disabled="disabled"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="累计规模"
            prop="size"
          >
            <BaseInput
              v-model="labourList.constructionProject.size"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
        <a-col
          :md="8"
          :sm="8"
        >
          <a-form-model-item
            label="项目所在地"
            prop="projectAddress"
          >
            <BaseInput
              v-model="labourList.constructionProject.projectAddress"
              :disabled="disabled"
              :max-length="30"
              placeholder="请输入"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
    <construction-project :labour-list="labourList" />
    <title-name
      style="margin-top:20px"
      title="相关方调查评价"
    />
    <investigation :labour-list="labourList" />
    <a-form-model
      ref="ruleForm3"
      :model="labourList.investigate"
      :label-col="{span: 6 }"
      :wrapper-col="{span: 18 }"
      :rules="rules"
      style="margin-top:20px"
    >
      <a-row>
        <a-col
          :md="12"
          :sm="12"
        >
          <a-form-model-item
            label="考察结论"
            class="radio-box"
            prop="result"
          >
            <a-radio-group
              v-model="labourList.investigate.result"
              :disabled="disabled"
              :max-length="30"
              name="radioGroup"
              :default-value="1"
            >
              <a-radio value="1">
                合格
              </a-radio>
              <a-radio value="2">
                不合格
              </a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col
          :md="12"
          :sm="12"
        >
          <a-form-model-item
            label="其他需要说明问题"
            prop="elseInformation"
          >
            <BaseInput
              v-model="labourList.investigate.elseInformation"
              :disabled="disabled"
              :max-length="300"
              type="textarea"
              placeholder="输入其他需要说明问题"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
    <a-button
      v-if="type != 'share'"
      style="float:right;"
      type="primary"
      @click="submitNextStep"
    >
      下一步
    </a-button>
  </div>
</template>

<script>
  import Company from './table/company'
  import Achievement from '@/views/subcontractors/investigate/components/table/Achievement'
  import team from '@/views/subcontractors/investigate/components/table/team'
  import constructionProject from '@/views/subcontractors/investigate/components/table/constructionProject'
  import investigation from '@/views/subcontractors/investigate/components/table/investigation'
  import {getlabourService , addlabourService ,editlabourService} from '@/api/subcontractors/subcontractors'
  import { isEmail, isPhone, isSocialcredit, createValidator} from '@/utils/regExpression'
  export default {
  name:'a'+Date.now(),
    components:{
      Company,
      Achievement,
      team,
      constructionProject,
      investigation
    },
    props:["labourList",'disabled'],
    data(){
      return{
        type:'',
        form:{
          investigate:{},
          constructionProject:{},
          subcontractorBase:{},
          lsebId:'',
        },
      // 校验规则
      rules: {
        // companyCreateTime	: [{ required: true, message: '请选择公司成立时间	', trigger: 'change' }],
        // registerCapital: [{ required: true, message: '请填写注册资金	', trigger: 'blur' }],
        // isFixed: [{ required: true, message: '请选择办公地址是否固定	', trigger: 'change' }],
        // address: [{ required: true, message: '请填写单位地址', trigger: 'blur' }],
        // legalName: [{ required: true, message: '请填写法定代表人姓名	', trigger: 'blur' }],
        // legalPhone: [{ required: true, message: '请填写法定代表人电话', trigger: 'blur' }],
        // investigateName: [{ required: true, message: '请填写考察联系人姓名	', trigger: 'blur' }],
        // investigatePhone	: [{ required: true, message: '请填写考察联系人电话	', trigger: 'blur' }],
        // license: [{ required: true, message: '请填写社会统一信用代码', trigger: 'blur' }],
        // qualificationCertificate	: [{ required: true, message: '请填写资质证书编号', trigger: 'blur' }],
        // qualityLevel: [{ required: true, message: '请填写资质类别等级', trigger: 'blur' }],
        // securityCode: [{ required: true, message: '请填写安全生产许可证编号', trigger: 'blur' }],
        // acturalName: [{ required: true, message: '请填写实际负责人姓名', trigger: 'blur' }],
        // acturalPhone: [{ required: true, message: '请填写实际负责人电话', trigger: 'blur' }],
        // investigateResult: [{ required: true, message: '请填写考察结论', trigger: 'blur' }],
        // elseInformation: [{ required: true, message: '请填写其他需要说明的问题', trigger: 'blur' }],
        // count: [{ required: true, message: '请填写目前在施项目个数', trigger: 'blur' }],
        // size: [{ required: true, message: '请填写累计规模', trigger: 'blur' }],
          legalPhone: [{ validator: createValidator(isPhone, '手机号格式不正确', false,this.validChanged), trigger: 'blur'}],
          acturalPhone: [{ validator: createValidator(isPhone, '手机号格式不正确', false,this.validChanged), trigger: 'blur'}],
          investigatePhone: [{ validator: createValidator(isPhone, '手机号格式不正确', false,this.validChanged), trigger: 'blur'}],
          license: [{ validator: createValidator(isSocialcredit, '社会统一信用代码格式不正确', false, this.validChanged), trigger: 'blur'}]
      },
      }
    },
    created() {
      this.id = this.$route.query.id
      this.type = this.$route.query.type
      if(this.$route.fullPath=='/project/subcontractors/investigate/view'){
        this.type='view'
      }
      // this.getlabourService()
      // this.addLabourBasic()
    },
    mounted(){
      // this.getlabourService()
    },
    methods:{
      validChanged(data) {
        this.$emit('validChanged', data)
      },
      getlabourService(){
        getlabourService({id:this.id}).then((res)=>{
          this.form = res.data
          // 办公地址是否固定
          if(this.labourList.subcontractorBase.isFixed=='1'){
            this.labourList.subcontractorBase.isFixed=1
          }else if(this.labourList.subcontractorBase.isFixed=='2'){
            this.labourList.subcontractorBase.isFixed=2
          }
          // 考察结果
          if(this.labourList.investigate.result=='1'){
            this.labourList.investigate.result=1
          }else if(this.labourList.investigate.result=='2'){
            this.labourList.investigate.result=2
          }
        })
      },
      // save(){
      //   console.log(this.labourList)
      //   this.labourList.investigateId = this.id
      //   this.labourList.evaluationId = this.labourList.subcontractorBase.evaluationId
      //   editlabourService(this.labourList).then(res=>{
      //   })
      // },
      submitNextStep(){
        console.log(this.labourList)
        // this.$refs.ruleForm1.validate(valid=>{
        //   if(valid){
        //     this.$refs.ruleForm2.validate(valid2=>{
        //       if(valid2){
        //         this.$refs.ruleForm3.validate(valid3=>{
        //           if(valid3){
                    this.$emit("submitNextStep",this.labourList)
        //           }
        //         })
        //       }
        //     })
        //   }
        // })
      },
      changecompanyCreateTime(value,dateString){
          this.labourList.subcontractorBase.companyCreateTime = dateString
      },
      addLabourBasic(){
        addLabourBasic({id:this.id}).then(res=>{
          this.lsebId = res.data
        })
      }
    }
  }
</script>

<!--<style scoped lang="less">-->
<!--.radio-box {-->
<!--    .ant-radio-wrapper {-->
<!--        position: static !important;-->
<!--    }-->
<!--    .ant-radio-group {-->
<!--        margin-top: 3% !important;-->
<!--        display: flex;-->
<!--    }-->
<!--}-->
<!--</style>-->
